package org.jsola.hr.task;

import com.alibaba.fastjson.JSON;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.jsola.common.DateKit8;
import org.jsola.hr.common.task.TaskKit;
import org.jsola.hr.constant.ExtraType;
import org.jsola.hr.dao.IAttendPlanDAO;
import org.jsola.hr.dao.IAttendPunchDailyReportDAO;
import org.jsola.hr.dao.IAttendPunchDailySummaryDAO;
import org.jsola.hr.dao.IAttendPunchRecordDAO;
import org.jsola.hr.dto.TaskAddDTO;
import org.jsola.hr.dto.attendrule.AttendRuleStaffAddDTO;
import org.jsola.hr.entity.*;
import org.jsola.hr.query.AttendExtraJsonQuery;
import org.jsola.hr.query.AttendPunchDeptQuery;
import org.jsola.hr.query.AttendPunchStaffQuery;
import org.jsola.hr.query.EmpDepQuery;
import org.jsola.hr.service.*;
import org.jsola.hr.vo.StaffVO;
import org.jsola.notice.constant.NoticeConstants;
import org.jsola.notice.constant.ReceiveDateTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.text.ParseException;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;


/**
 * 考勤打卡提醒
 * 每日定时任务：根据考勤规则和考勤日历创建定时任务给用户发送打卡提醒（公众号推送）
 * @author zhuhaoran
 */
@Component
@Slf4j
public class AttendPunchRemindTask {
    @Autowired
    private IAttendRuleService attendRuleService;

    /**
     * 考勤打卡-通知
     */
    @XxlJob("attendPunchRemindTask")
    public ReturnT<String> attendPunchRemind(String params) {
        XxlJobLogger.log("==========定时任务开始: 考勤打卡发送通知");
        try {
            attendRuleService.attendPunchRemind();
        } catch (Exception e) {
            XxlJobLogger.log("==========定时任务失败: 考勤打卡发送通知,失败原因 : {}", e.getMessage());
            log.error("定时任务失败: 考勤打卡发送通知,失败原因:", e);
            return ReturnT.FAIL;
        }
        XxlJobLogger.log("==========定时任务结束: 考勤打卡发送通知");
        return ReturnT.SUCCESS;
    }

}
